package com.example.demo.service;

import com.example.demo.pojo.entity.Course;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

// 后端服务类
public class BackendService {
    private Map<Integer, Course> courseMap;
    private int nextCourseCode;

    public BackendService() {
        this.courseMap = new HashMap<>();
        this.nextCourseCode = 100001;
    }

    // 添加收藏课程
    public void addFavorite(String name, String image) {
        Course course = new Course(nextCourseCode++, name, image);
        courseMap.put(course.getCode(), course);
    }

    // 获取所有收藏课程
    public List<Course> getFavorites() {
        return new ArrayList<>(courseMap.values());
    }
}
